package com.wkq.controller;

import com.wkq.domain.Product;
import com.wkq.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "/product")
public class ProductController {

    @Autowired
    private IProductService iProductService;

//    查询全部产品
    @RequestMapping(value = "/findAll")
    @ResponseBody
    public ModelAndView findAll () {
        ModelAndView mv = new ModelAndView();
        List<Product> list = iProductService.findAll();
        mv.addObject("productList", list);
        mv.setViewName("product-list");
        return mv;
    }

//    添加产品
    @RequestMapping(value = "/save")
    public String insertSingleData(Product product) {
        iProductService.insertSingleData(product);
        return "redirect:findAll";
    }

}
